import { Item } from "../shared/face/index";
import sdk from '../core/index';
import { quality, ItemType, qualityName } from "../shared/face/enums";

export class Bag {
    items: Map<string, Item> = new Map();
    constructor() {

    }
    addItem(item: Item) {
        // 如果是其他类型的物品，检查是否已经存在
        if (this.items.has(item.id)) {
            // 如果存在，叠加数量
            const existingItem = this.items.get(item.id);
            if (existingItem) {
                existingItem.count += item.count;
            }
        } else {
            // 如果不存在，直接添加
            this.items.set(item.id, item);
        }
    }
    getCard(title: string = '获得奖励') {
        let card = sdk.tool.card.create();
        if (this.items.size == 0) {
            console.log(`Bag.getCard - 物品数量为0，返回空卡片`);
            return card;
        }
        console.log(`Bag.getCard - 生成奖励卡片，物品数量: ${this.items.size}`);
        card.title(title);
        this.items.forEach((item, key) => {
            switch (item.type) {
                case ItemType.装备:
                    card.l(`${item.emoji}${Object.values(qualityName)[item.quality]}·${item.name}`);
                    break;
                default:
                    if (item.count == 1) {
                        card.l(`${item.emoji}${item.name}`);
                    } else {
                        card.l(`${item.emoji}${item.name}x${item.count}`);
                    }
                    break;
            }

        });
        return card;
    }
}

